﻿package com.tudou.home.newskin.panel
{
    import com.tudou.cookie.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.newskin.buttons.*;
    import com.tudou.home.newskin.consts.*;
    import com.tudou.home.newskin.containers.*;
    import com.tudou.home.newskin.events.*;
    import com.tudou.home.newskin.model.*;
    import com.tudou.skin.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class MainPanel extends Sprite implements IPlayer, IVideoSize, IRate, IFullscreen, IVideoAudio, IAdFloatCorner, IAdOverlay, IPlayList, ITransform, IMove, IShare, IInitVideo, IRelativeVideo, IPlayComplete, IExpand, IStream, IOriginalInfo, ICopyright, IAdPauseSpec, ITipInfo, ITime, ISetting, ITransFinished
    {
        private var goHeight:uint;
        private var movePercent:Number = 1;
        private var isPlayList:Boolean = false;
        private var bigPlay:InteractiveObject;
        private var bigPlayVisible:Boolean = false;
        private var video:VideoSprite;
        private var isFullscreen:Boolean;
        private var adOverlay:DisplayObject;
        private var goWidth:uint;
        private var playFinished:PlayFinishedSprite;
        private var adCornerFloatSprite:AdCornerFloatSprite;
        private var backgroundFrame:DisplayObject;
        private var loadingDisplay:DisplayObject;
        private var audioShow:DisplayObject;
        var infoPanel:InfoPanel;

        public function MainPanel()
        {
            video = new VideoSprite();
            addChild(video);
            loadingDisplay = new LoadingTudou();
            addChild(loadingDisplay);
            backgroundFrame = new BackgroundFrame();
            addChild(backgroundFrame);
            bigPlay = new BigPlayBTN();
            bigPlay.x = int(bigPlay.width / 2) + 6;
            addChild(bigPlay);
            adCornerFloatSprite = new AdCornerFloatSprite();
            addChild(adCornerFloatSprite);
            infoPanel = new InfoPanel();
            addChild(infoPanel);
            playFinished = new PlayFinishedSprite();
            addChild(playFinished);
            init();
            initListeners();
            return;
        }// end function

        public function setTotalTime(param1:Number) : void
        {
            infoPanel.setTotalTime(param1);
            return;
        }// end function

        private function mouseClickHlr(event:MouseEvent) : void
        {
            if (event.currentTarget == bigPlay)
            {
                dispatchEvent(new SkinEvent(SkinEvent.PLAY, false));
            }
            return;
        }// end function

        public function setRelativeList(param1:Array) : void
        {
            playFinished.setRelativeList(param1);
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        public function setShareItemList(param1:Array) : void
        {
            playFinished.setShareItemList(param1);
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        private function initListeners() : void
        {
            bigPlay.addEventListener(MouseEvent.CLICK, mouseClickHlr);
            return;
        }// end function

        private function init() : void
        {
            isFullscreen = false;
            goWidth = PlayerConsts.MAIN_WIDTH;
            goHeight = PlayerConsts.MAIN_HEIGHT;
            playFinished.visible = false;
            loadingDisplay.visible = false;
            bigPlay.visible = bigPlayVisible;
            goTransform(PlayerConsts.DEFAULT_VIDEO_WIDTH, PlayerConsts.DEFAULT_VIDEO_HEIGHT, false);
            return;
        }// end function

        public function showError(param1:int) : void
        {
            infoPanel.showError(param1);
            return;
        }// end function

        public function getIndex() : int
        {
            return 0;
        }// end function

        public function stopTransFinishTimeout() : void
        {
            playFinished.stopTransFinishTimeout();
            return;
        }// end function

        public function paused() : void
        {
            video.paused();
            bigPlayVisible = true;
            bigPlay.visible = bigPlayVisible;
            infoPanel.paused();
            return;
        }// end function

        public function setAdFloat(param1:DisplayObject) : void
        {
            adCornerFloatSprite.setAdFloat(param1);
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        public function setOriginalWidthHeight(param1:int, param2:int) : void
        {
            video.setOriginalWidthHeight(param1, param2);
            infoPanel.setOriginalWidthHeight(param1, param2);
            return;
        }// end function

        public function loading() : void
        {
            loadingDisplay.visible = true;
            video.loading();
            bigPlayVisible = false;
            bigPlay.visible = bigPlayVisible;
            video.setEnableClick(false);
            return;
        }// end function

        public function playing() : void
        {
            video.playing();
            bigPlayVisible = false;
            bigPlay.visible = bigPlayVisible;
            video.setEnableClick(true);
            infoPanel.playing();
            return;
        }// end function

        public function completed() : void
        {
            video.completed();
            bigPlayVisible = false;
            bigPlay.visible = bigPlayVisible;
            infoPanel.completed();
            return;
        }// end function

        public function addVideo(param1:DisplayObject) : void
        {
            video.addVideo(param1);
            return;
        }// end function

        public function showComplete() : void
        {
            playFinished.visible = true;
            playFinished.showComplete();
            return;
        }// end function

        public function setRate(param1:int) : void
        {
            video.setRate(param1);
            infoPanel.setRate(param1);
            return;
        }// end function

        public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            var _loc_5:uint = 0;
            var _loc_6:uint = 0;
            var _loc_4:* = PlayerConsts.BACKGROUND_FRAME_THICKNESS;
            isFullscreen = param3;
            goWidth = param1;
            goHeight = param2;
            graphics.clear();
            graphics.beginFill(0);
            graphics.drawRect(0, 0, goWidth, goHeight);
            graphics.endFill();
            if (isFullscreen)
            {
                video.x = 0;
                video.y = 0;
                video.goTransform(goWidth, goHeight, isFullscreen);
            }
            else
            {
                video.x = _loc_4;
                video.y = _loc_4;
                video.goTransform(goWidth - _loc_4 * 2, goHeight - _loc_4 * 2, isFullscreen);
            }
            loadingDisplay.x = video.x;
            loadingDisplay.y = video.y;
            loadingDisplay.width = goWidth - _loc_4 * 2;
            loadingDisplay.height = goHeight - _loc_4 * 2;
            backgroundFrame.width = goWidth;
            backgroundFrame.height = goHeight;
            playFinished.x = video.x;
            playFinished.y = video.y;
            if (isFullscreen)
            {
                _loc_5 = goWidth;
                _loc_6 = goHeight;
            }
            else
            {
                _loc_5 = goWidth - _loc_4 * 2;
                _loc_6 = goHeight - _loc_4;
            }
            playFinished.goTransform(_loc_5, _loc_6, isFullscreen);
            if (isFullscreen)
            {
                bigPlay.y = int(goHeight - PlayerConsts.CONTROL_DEFAULT_HEIGTH - bigPlay.width / 2 - NewSkinConsts.INFO_PANEL_HEIGHT - 8);
                if (isPlayList)
                {
                    bigPlay.y = bigPlay.y - NewSkinConsts.PLAYLIST_HEIGHT;
                }
            }
            else
            {
                bigPlay.y = int(goHeight - bigPlay.height / 2 - NewSkinConsts.INFO_PANEL_HEIGHT) - 6;
            }
            if (adOverlay)
            {
                adOverlay.x = video.x;
                adOverlay.y = int(goHeight - AdSize.OVERLAY_HEIGHT);
                if (isFullscreen)
                {
                    adOverlay.y = adOverlay.y - PlayerConsts.CONTROL_DEFAULT_HEIGTH;
                }
                if (isPlayList && isFullscreen)
                {
                    adOverlay.y = adOverlay.y - NewSkinConsts.PLAYLIST_HEIGHT;
                }
            }
            adCornerFloatSprite.x = int(goWidth - adCornerFloatSprite.width);
            adCornerFloatSprite.y = int(goHeight - adCornerFloatSprite.height);
            if (isFullscreen)
            {
                adCornerFloatSprite.y = adCornerFloatSprite.y - PlayerConsts.CONTROL_DEFAULT_HEIGTH;
            }
            if (isPlayList && isFullscreen)
            {
                adCornerFloatSprite.y = adCornerFloatSprite.y - NewSkinConsts.PLAYLIST_HEIGHT;
            }
            if (audioShow)
            {
                audioShow.x = int((goWidth - audioShow.width) / 2);
                audioShow.y = int(goHeight - audioShow.height - 4);
                if (isFullscreen)
                {
                    audioShow.y = audioShow.y - PlayerConsts.CONTROL_DEFAULT_HEIGTH;
                }
            }
            infoPanel.goTransform(goWidth - AdSize.CORNER_WIDTH, goHeight, isFullscreen);
            if (isFullscreen)
            {
                infoPanel.y = int(goHeight - PlayerConsts.CONTROL_DEFAULT_HEIGTH - infoPanel.height);
                if (isPlayList)
                {
                    infoPanel.y = infoPanel.y - NewSkinConsts.PLAYLIST_HEIGHT;
                }
            }
            else
            {
                infoPanel.y = int(goHeight - infoPanel.height);
            }
            return;
        }// end function

        public function getRate() : int
        {
            return video.getRate();
        }// end function

        public function getVideoSize() : int
        {
            return video.getVideoSize();
        }// end function

        public function setAdOverlay(param1:DisplayObject) : void
        {
            removeAdOverlay();
            adOverlay = param1;
            var _loc_2:* = getChildIndex(infoPanel);
            addChildAt(adOverlay, (_loc_2 + 1));
            goTransform(goWidth, goHeight, isFullscreen);
            if (isFullscreen)
            {
                move(movePercent);
            }
            return;
        }// end function

        public function setPlayList(param1:Array) : void
        {
            isPlayList = true;
            return;
        }// end function

        public function showTip(param1:int) : void
        {
            infoPanel.showTip(param1);
            return;
        }// end function

        public function set showTransFinished(param1:Boolean) : void
        {
            playFinished.showTransFinished = param1;
            return;
        }// end function

        public function exitFullscreen() : void
        {
            backgroundFrame.visible = true;
            playFinished.exitFullscreen();
            return;
        }// end function

        public function setPlaylistSingleContinue(param1:Boolean) : void
        {
            playFinished.setPlaylistSingleContinue(param1);
            return;
        }// end function

        public function setSkipHeadTailValue(param1:Number, param2:Number) : void
        {
            infoPanel.setSkipHeadTailValue(param1, param2);
            return;
        }// end function

        public function startTransFinishTimeout() : void
        {
            playFinished.startTransFinishTimeout();
            return;
        }// end function

        public function removeAdOverlay() : void
        {
            if (adOverlay)
            {
                removeChild(adOverlay);
                adOverlay = null;
            }
            return;
        }// end function

        public function setRateSetting(param1:RateSettingData) : void
        {
            infoPanel.setRateSetting(param1);
            return;
        }// end function

        public function setCopyright(param1:Boolean) : void
        {
            var value:* = param1;
            if (value)
            {
                setTimeout(function () : void
            {
                infoPanel.showError(2);
                return;
            }// end function
            , 200);
            }
            else
            {
                infoPanel.clearTipInfo(InfoPanel.CLOSE_BUTTON);
            }
            return;
        }// end function

        public function setIndex(param1:int) : void
        {
            return;
        }// end function

        public function showSettingSkipTip() : void
        {
            infoPanel.showSettingSkipTip();
            return;
        }// end function

        public function hideComplete() : void
        {
            playFinished.visible = false;
            playFinished.hideComplete();
            return;
        }// end function

        public function setExpand(param1:Boolean) : void
        {
            playFinished.setExpand(param1);
            return;
        }// end function

        public function buffering() : void
        {
            video.buffering();
            infoPanel.buffering();
            return;
        }// end function

        public function ready() : void
        {
            video.ready();
            bigPlayVisible = false;
            bigPlay.visible = bigPlayVisible;
            loadingDisplay.visible = false;
            infoPanel.ready();
            return;
        }// end function

        public function hasSkipHeadTail(param1:Boolean) : void
        {
            infoPanel.hasSkipHeadTail(param1);
            return;
        }// end function

        public function setMaxRate(param1:int, param2:Boolean) : void
        {
            video.setMaxRate(param1, param2);
            infoPanel.setMaxRate(param1, param2);
            return;
        }// end function

        public function setPlayTime(param1:Number) : void
        {
            infoPanel.setPlayTime(param1);
            return;
        }// end function

        public function enterFullscreen() : void
        {
            backgroundFrame.visible = false;
            playFinished.enterFullscreen();
            return;
        }// end function

        public function setBaseVideoInfo(param1:IBaseVideoInfo) : void
        {
            playFinished.setBaseVideoInfo(param1);
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        public function setSkipSeting(param1:SkipSettingData) : void
        {
            infoPanel.setSkipSeting(param1);
            return;
        }// end function

        public function showSettingedSkipTip() : void
        {
            infoPanel.showSettingedSkipTip();
            return;
        }// end function

        public function canMoveOut() : Boolean
        {
            return true;
        }// end function

        public function move(param1:Number) : void
        {
            movePercent = param1;
            var _loc_2:* = PlayerConsts.CONTROL_DEFAULT_HEIGTH + NewSkinConsts.INFO_PANEL_HEIGHT;
            if (isPlayList)
            {
                _loc_2 = _loc_2 + NewSkinConsts.PLAYLIST_HEIGHT;
            }
            bigPlay.y = int(goHeight - bigPlay.height / 2 - 8 - _loc_2 * param1);
            var _loc_3:* = PlayerConsts.CONTROL_DEFAULT_HEIGTH;
            if (isPlayList)
            {
                _loc_3 = _loc_3 + NewSkinConsts.PLAYLIST_HEIGHT;
            }
            adCornerFloatSprite.y = int(goHeight - adCornerFloatSprite.height - _loc_3 * param1);
            if (adOverlay)
            {
                adOverlay.y = int(goHeight - AdSize.OVERLAY_HEIGHT - _loc_3 * param1);
            }
            infoPanel.y = int(goHeight - infoPanel.height - _loc_3 * param1);
            return;
        }// end function

        public function isAudio(param1:Boolean) : void
        {
            if (param1)
            {
                if (audioShow == null)
                {
                    audioShow = new AudioShowMC();
                    addChildAt(audioShow, (getChildIndex(video) + 1));
                    goTransform(goWidth, goHeight, isFullscreen);
                }
            }
            else if (audioShow != null)
            {
                removeChild(audioShow);
                audioShow = null;
            }
            video.setVideoVisible(!param1);
            return;
        }// end function

        public function clearTipInfo(param1:int) : void
        {
            infoPanel.clearTipInfo(param1);
            return;
        }// end function

        public function setVideoSize(param1:int) : void
        {
            video.setVideoSize(param1);
            return;
        }// end function

        public function setOriginalRate(param1:Number) : void
        {
            video.setOriginalRate(param1);
            infoPanel.setOriginalRate(param1);
            return;
        }// end function

        public function setAdCorner(param1:DisplayObject) : void
        {
            adCornerFloatSprite.setAdCorner(param1);
            goTransform(goWidth, goHeight, isFullscreen);
            return;
        }// end function

        public function bufferEmpty() : void
        {
            video.bufferEmpty();
            return;
        }// end function

        public function bufferFull() : void
        {
            video.bufferFull();
            return;
        }// end function

        public function showFastTip(param1:Boolean = false) : void
        {
            infoPanel.showFastTip(param1);
            return;
        }// end function

    }
}
